<html>
<head><meta charset="utf-8"><title>cross-rustc · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html">cross-rustc</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="211895066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211895066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Greaves <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211895066">(Oct 01 2020 at 11:13)</a>:</h4>
<p>Hi.<br>
I work on an open-source OS/distro for mobile (arm) devices (SailfishOS). I'm trying to build rust to work in our build system.<br>
The goal is to build a rustc which has build=x86 host=x86 and target=armv7-unknown-linux-gnueabihf<br>
Ie the <em>default</em> from a --print target-spec-json would say armv7*</p>
<p>This matters because solutions like wrapping rustc and specifying --target isn't quite the same wrt target dirs and other stuff<br>
The reason I need this is to do with how we optimise the cross-build process for the distro (ie rather than qemu an arm rustc we intercept the call to rustc and directly run an x86 cross-rustc... someone would have asked "why?" :D )</p>
<p>As it stands I can build our arm crates in x86 land using ./configure --build=i686-unknown-linux-gnu --host=i686-unknown-linux-gnu --target=armv7-unknown-linux-gnueabihf<br>
But the rustc doesn't produce armv7 code by default</p>
<p>OK - hope that's enough of a conversation starter</p>



<a name="211895900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211895900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211895900">(Oct 01 2020 at 11:24)</a>:</h4>
<p>If you make rustc compile for a different target than the host by default, you will not be able to build any crates that use build scripts or proc-macros, as those must be compiled for the host. Why is using <code>--target</code> a problem? The build dir is just <code>target/$TARGET_TRIPLE</code> instead of <code>target</code>.</p>



<a name="211896269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211896269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Greaves <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211896269">(Oct 01 2020 at 11:29)</a>:</h4>
<p>this rustc will run inside an arm 'host' it is not [edited] used as a cross compiler in the normal sense. Better to think of it as an armv7 rustc emulator.</p>



<a name="211896382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211896382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211896382">(Oct 01 2020 at 11:31)</a>:</h4>
<p>Then the rustc itself should be compiled for arm, right?</p>



<a name="211896415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211896415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211896415">(Oct 01 2020 at 11:31)</a>:</h4>
<p>Ah, nevermind. Read the piece about intercepting it.</p>



<a name="211896416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211896416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Greaves <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211896416">(Oct 01 2020 at 11:31)</a>:</h4>
<p>no - see my post about someone asking why :D :D</p>



<a name="211896485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211896485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Greaves <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211896485">(Oct 01 2020 at 11:32)</a>:</h4>
<p>I do get that this is an unusual request.. ty for asking/helping</p>



<a name="211896495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211896495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211896495">(Oct 01 2020 at 11:32)</a>:</h4>
<p>Can't the intercept code add <code>--target armv7-unknown-linux-gnueabihf</code>?</p>



<a name="211896526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211896526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Greaves <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211896526">(Oct 01 2020 at 11:33)</a>:</h4>
<p>one use case is to build gecko... imagine the chaos hacking that build system when the paths change...</p>



<a name="211896549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211896549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211896549">(Oct 01 2020 at 11:33)</a>:</h4>
<p>If you only add <code>--target</code> to the rustc invocation and not cargo, all paths remain the same.</p>



<a name="211896551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211896551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Greaves <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211896551">(Oct 01 2020 at 11:33)</a>:</h4>
<p>I did try fwiw - but then you need to hack all kinds of things with cargo etc.</p>



<a name="211896628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211896628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Greaves <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211896628">(Oct 01 2020 at 11:34)</a>:</h4>
<p>sometimes cargo passes --target... then the wrapper needs to parse the args and strip that passed --target</p>



<a name="211896653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211896653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Greaves <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211896653">(Oct 01 2020 at 11:34)</a>:</h4>
<p>otherwise rustc blows up with 2 --target options .. <em>sigh</em></p>



<a name="211896661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211896661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211896661">(Oct 01 2020 at 11:34)</a>:</h4>
<p><code>--target</code> should only be passed when you also pass <code>--target</code> to cargo.</p>



<a name="211896675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211896675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Greaves <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211896675">(Oct 01 2020 at 11:35)</a>:</h4>
<p>which can happen</p>



<a name="211896703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211896703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Greaves <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211896703">(Oct 01 2020 at 11:35)</a>:</h4>
<p>the point is that ./configure says that --target should do exactly what I want</p>



<a name="211896858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211896858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211896858">(Oct 01 2020 at 11:37)</a>:</h4>
<p>I can't find that anywhere. <code>--target</code> is for specifying which targets to build a standard library for, not setting the default: <a href="https://github.com/rust-lang/rust/blob/fc42fb8e70af6ad63998f4bfbf62451551eda073/config.toml.example#L177">https://github.com/rust-lang/rust/blob/fc42fb8e70af6ad63998f4bfbf62451551eda073/config.toml.example#L177</a></p>



<a name="211896988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211896988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211896988">(Oct 01 2020 at 11:38)</a>:</h4>
<p>I think you can override the triple rustc thinks is the host triple here: <a href="https://github.com/rust-lang/rust/blob/fc42fb8e70af6ad63998f4bfbf62451551eda073/compiler/rustc_session/src/config.rs#L612">https://github.com/rust-lang/rust/blob/fc42fb8e70af6ad63998f4bfbf62451551eda073/compiler/rustc_session/src/config.rs#L612</a></p>



<a name="211897145"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211897145" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Greaves <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211897145">(Oct 01 2020 at 11:40)</a>:</h4>
<p>Ah - I see - I probably misunderstood that the first time I read it and never really re-read the words in detail.</p>



<a name="211897203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211897203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Greaves <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211897203">(Oct 01 2020 at 11:41)</a>:</h4>
<p>I was on "Which triples to produce a compiler toolchain for" ... which is exactly gcc-speak for a cross-compiler</p>



<a name="211897369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211897369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Greaves <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211897369">(Oct 01 2020 at 11:43)</a>:</h4>
<p>and <em>thank you</em> for the pointer to the code - I don't mind applying a patch to change that default locally - I did actually try and find this but my rust-foo wasn't up to it.</p>



<a name="211897492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211897492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211897492">(Oct 01 2020 at 11:44)</a>:</h4>
<p>I recently looked at that part of code myself, so it wasn't too hard to find.</p>



<a name="211897979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211897979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Greaves <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211897979">(Oct 01 2020 at 11:50)</a>:</h4>
<p>Now I need to learn enough rust to actually change that code... more fun than "hello world!"</p>



<a name="211903702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211903702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211903702">(Oct 01 2020 at 12:47)</a>:</h4>
<p>rustc is not gcc, rustc is LLVM, and so it comes to the crux of the matter: rustc is a cross compiler by default.</p>



<a name="211906703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211906703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211906703">(Oct 01 2020 at 13:10)</a>:</h4>
<p>I am not sure this is not better served via a .cargo/config</p>



<a name="211906992"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211906992" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211906992">(Oct 01 2020 at 13:13)</a>:</h4>
<p>also I would be genuinely surprised if you are running i686 and not x86_64 machines (I say, warming up some genuine surprise just in case.)</p>



<a name="211924846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211924846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Greaves <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211924846">(Oct 01 2020 at 15:08)</a>:</h4>
<p>Well, the weather is getting cold so that nice warm surprise should help ;)</p>
<p>The project started back in 2009 in partnership with Intel and we do still use i486 (not i686) as the primary build environment. IIRC there was some stuff they hacked into the libc code to use Intel specific bits of Celeron which stopped it running on AMD chips - hence i486 and not i386. That code is long gone but our gcc triplet is still visible:<br>
  --set target.%{rust_ttriple}.cc=/opt/cross/bin/armv7hl-meego-linux-gnueabi-cc </p>
<p>We do have aarch64 ports of the actual OS now though</p>



<a name="211962423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cross-rustc/near/211962423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cross-rustc.html#211962423">(Oct 01 2020 at 19:32)</a>:</h4>
<p>well then!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>